"use strict";

let TAX_RATE = 0.001;
let HANDOVER_RATE = 0.00002;
let PASS_RATE = 0.0000687;
let FEE_RATE = 0.00025;
let MAX_FEE_RATE = 0.003;
let MIN_FEE = 5.00;

function bidAskPriceQuickDiffSH(bid_price, ask_price, turns) {

    let ask_sum = ask_price * turns;
    let bid_sum = bid_price * turns;

    let ask_fee = getTotalAskFeeSH(ask_sum);
    let bid_fee = getTotalBidFeeSH(bid_sum);

    ask_sum = ask_sum - ask_fee;
    bid_sum = bid_sum - bid_fee;

    return ask_sum - bid_sum;

}

function getTotalAskFeeSH(total_ask_sum) {
    let tax_sum = total_ask_sum * TAX_RATE;
    let handover_sum = total_ask_sum * HANDOVER_RATE;
    let pass_sum = total_ask_sum * PASS_RATE;
    let fee_sum = total_ask_sum * FEE_RATE;
    let max_fee_sum = total_ask_sum * MAX_FEE_RATE;

    if (fee_sum < MIN_FEE) {
        fee_sum = MIN_FEE;
    }

    if (fee_sum > max_fee_sum) {
        fee_sum = max_fee_sum;
    }

    return tax_sum + handover_sum + pass_sum + fee_sum;
}

function getTotalBidFeeSH(total_bid_sum) {
    let handover_sum = total_bid_sum * HANDOVER_RATE;
    let pass_sum = total_bid_sum * PASS_RATE;
    let fee_sum = total_bid_sum * FEE_RATE;
    let max_fee_sum = total_bid_sum * MAX_FEE_RATE;

    if (fee_sum < MIN_FEE) {
        fee_sum = MIN_FEE;
    }

    if (fee_sum > max_fee_sum) {
        fee_sum = max_fee_sum;
    }

    return handover_sum + pass_sum + fee_sum;
}